package com.tantou.leetcode.easy;

/**
 * @author jiangweiyang
 * @created 2020/4/30 13:16
 **/
public class IsPalindrome {

    /**
     * https://leetcode-cn.com/problems/palindrome-number/submissions/
     */
    public static void main(String[] args) {
        System.out.println(isPalindrome(121));
    }

    public static boolean isPalindrome(int x) {
        //如果小于0 或者可以被10整除，即整数都不是回文数
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        int originalX = x;
        int ret = 0;
        while (x > 0) {
            ret = ret * 10 + x % 10;
            x = x / 10;
        }
        return originalX == ret;
    }
}
